home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 32 / Mac Magazin and MacEasy Magazine CD - Issue 32.iso / Multimedia / PlayerPRO 4.5.5 Dev.Kit / Plug-Ins / Sound Filters Plugs / CrossFade.c < prev    next >
C/C++ Source or Header  |  1995-10-08  |  3KB  |  105 lines

  1. /*    CrossFade        */
  2. /*    v 0.3            */
  3. /*    1995 by Liane    */
  4.  
  5. //    Usage:
  6. //    After setting a not-so-bad loop, do loop-to-selection
  7. //    then crossfade. It will remove the click that might
  8. //    appear at the end of the loop, and also linearize
  9. //    the harmonic content in it.
  10.  
  11. #include "MAD.h"
  12. #include "PPPlug.h"
  13.  
  14. #if defined(powerc) || defined(__powerc)
  15. enum {
  16.         PlayerPROPlug = kCStackBased
  17.         | RESULT_SIZE(SIZE_CODE( sizeof(OSErr)))
  18.         | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof( sData*)))
  19.         | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof( long)))
  20.         | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof( long)))
  21.         | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof( PPInfoPlug*)))
  22. };
  23.  
  24. ProcInfoType __procinfo = PlayerPROPlug;
  25. #else
  26. #include <A4Stuff.h>
  27. #endif
  28.  
  29.  
  30. #define min(a,b) (((a) < (b)) ? (a) : (b))
  31.  
  32. OSErr main(     sData                    *theData,
  33.                 long                    SelectionStart,
  34.                 long                    SelectionEnd,
  35.                 PPInfoPlug                *thePPInfoPlug)
  36. {
  37.     switch( theData->amp)
  38.     {
  39.         case 8:
  40.         {
  41.             long    i, j, length = (SelectionEnd - SelectionStart) / 2;
  42.             long    temp, tempStart, tempEnd;
  43.             Ptr        StartPtr, EndPtr;
  44.         
  45.             length = min (length, theData->size - SelectionEnd);
  46.             length = min (length, SelectionStart);
  47.             length *= 2;
  48.             
  49.             for( j = 0; j < 2; j++)    //do it twice
  50.             {
  51.                 StartPtr = theData->data + SelectionStart - (length / 2);
  52.                 EndPtr = theData->data + SelectionEnd - (length / 2);
  53.                 for( i = 0; i < length; i++)
  54.                 {
  55.                     tempStart = *StartPtr;
  56.                     tempEnd = *EndPtr;
  57.             
  58.                     temp = ((tempEnd * i) + (tempStart * (length - i))) / length;
  59.                     if( temp > 127) temp = 127;
  60.                     else if( temp < -127 ) temp = -127;
  61.                     *StartPtr++ = temp;
  62.             
  63.                     temp = ((tempStart * i) + (tempEnd * (length - i))) / length;
  64.                     if( temp > 127) temp = 127;
  65.                     else if( temp < -127 ) temp = -127;
  66.                     *EndPtr++ = temp;
  67.                 }
  68.             }
  69.         } break;
  70.  
  71.         case 16:
  72.         {
  73.             long    i, j, length = (SelectionEnd - SelectionStart) / 2;
  74.             long    temp, tempStart, tempEnd;
  75.             short    *StartPtr, *EndPtr;
  76.         
  77.             length = min (length, theData->size - SelectionEnd);
  78.             length = min (length, SelectionStart);
  79. //            length *= 2;
  80.             
  81.             for( j = 0; j < 2; j++)    //do it twice
  82.             {
  83.                 StartPtr = (short*) theData->data + (SelectionStart / 2) - (length / 2);
  84.                 EndPtr = (short*) theData->data + (SelectionEnd / 2) - (length / 2);
  85.                 for( i = 0; i < length; i++)
  86.                 {
  87.                     tempStart = *StartPtr;
  88.                     tempEnd = *EndPtr;
  89.             
  90.                     temp = ((tempEnd * i) + (tempStart * (length - i))) / length;
  91.                     if( temp >= (short)0x7FFF) temp = 0x7FFF;    // overflow ?
  92.                     else if( temp <= (short)0x8000 ) temp = (short)0x8000;
  93.                     *StartPtr++ = temp;
  94.             
  95.                     temp = ((tempStart * i) + (tempEnd * (length - i))) / length;
  96.                     if( temp >= (short)0x7FFF) temp = 0x7FFF;    // overflow ?
  97.                     else if( temp <= (short)0x8000 ) temp = (short)0x8000;
  98.                     *EndPtr++ = temp;
  99.                 }
  100.             }
  101.         } break;
  102.     }
  103.     
  104.     return noErr;
  105. }